<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加销售订单</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 组件样式 -->
    <link rel="stylesheet" href="../../../elementUI/index.css">
    <link rel="stylesheet" href="../../../css/index.css">
    <style>
        .el-input .el-input__inner ,.el-input.is-disabled .el-input__inner ,
        .el-textarea .el-textarea__inner ,.el-textarea.is-disabled .el-textarea__inner{
          color: #000;
        }
    </style>
</head>

<!-- 代码结构 -->

<body>
    <div id="app" class="minWidth">
        <el-form :model="form" ref="contract" :rules="rules" inline-message="true" style="width: 100%">
            <div class="table_titel">
                <div class="titel">销售订单</div>
            </div>
            <el-descriptions :column="3" border size="small">
                </el-descriptions-item>
                <el-descriptions-item label="销售订单流水号">
                    <el-form-item prop="Sales_Order_SerialNumber">
                        <el-input v-model.trim="form.Sales_Order_SerialNumber" placeholder="请输入销售订单流水号"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item v-if="OrderType==0" label="经销商">
                    <el-form-item prop="Store_SerialNumber">
                        <el-select v-model.trim="form.Store_SerialNumber" placeholder="请选择经销商" clearable filterable style="width: 100%">
                            <el-option v-for="(item,index) in dealer" :key="index" :label="item.Dealer_Name" :value="item.Tax_Number"></el-option>
                        </el-select>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item v-else label="供货店铺">
                    <el-form-item prop="Store_SerialNumber">
                        <el-select v-model.trim="form.Store_SerialNumber" placeholder="可选择供货店铺" clearable filterable style="width: 100%">
                            <el-option v-for="(item,index) in store" :key="index" :label="item.Store_Name" :value="item.Store_SerialNumber"></el-option>
                        </el-select>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="联系电话">
                    <el-form-item prop="Sales_Phone">
                        <el-input v-model.trim="form.Sales_Phone" placeholder="请输入联系电话"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="销售地址">
                    <el-form-item prop="Address">
                        <el-cascader v-model="Address" @change="handleAddress" filterable :props="{value:'label'}" clearable :options="city"  style="width: 100%"></el-cascader>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="详细地址">
                    <el-form-item prop="AddressDetail">
                        <el-input :disabled="Address.length!=3" v-model.trim="AddressDetail" placeholder="请输入详细地址"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="顾客姓名">
                    <el-form-item prop="Sales_Contacts">
                        <el-input v-model.trim="form.Sales_Contacts" placeholder="可输入顾客姓名"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="顾客留言">
                    <el-form-item prop="Sales_Message">
                        <el-input v-model.trim="form.Sales_Message" placeholder="可输入顾客留言"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="下单日期">
                    <el-form-item prop="Sales_Date">
                        <el-date-picker v-model.trim="form.Sales_Date" type="datetime" placeholder="请选择下单日期" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="销售金额">
                    <el-form-item prop="Sales_Amount">
                        <el-input disabled v-model.trim="form.Sales_Amount" placeholder="请输入销售金额"></el-input>
                    </el-form-item>
                </el-descriptions-item>
            </el-descriptions>

            <div class="table_titel">
                <div class="titel">销售订单明细</div>
                <div class="operation">
                    <el-button type="primary" size="small" @click="add_sales_order_detail">新增</el-button>
                    <el-button type="danger" size="small" @click="remove_sales_order_detail">删除</el-button>
                </div>
            </div>
            <el-descriptions :style="form.Children.sales_order_detail.length-1==index?'margin-bottom: 100px;':'margin-bottom: 10px;'" 
                :column="3" border size="small" v-for="(item,index) in form.Children.sales_order_detail" :key="index">
                <el-descriptions-item label="有/无货货主">
                    <el-form-item>
                        <el-radio-group @change="ChangeRadio($event,index)" v-model="item.Sign">
                            <el-radio label="无货货主" value="0"></el-radio>
                            <el-radio label="有货货主" value="1"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item v-if="item.Sign=='无货货主'" label="商品名称">
                    <el-form-item>
                      <el-select v-model.trim="item.Article_SerialNumber" placeholder="请选择商品" filterable
                        @change="Change_Unit_Price(index,item)" style="width: 100%">
                        <el-option v-for="(ite,index) in article.filter(i=>i.Sign=='1')" :key="index"
                          :label="ite.Article_Name+'(所属企业:'+ite.Enterprise_Name+')'"
                          :value="ite.Article_SerialNumber"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-descriptions-item>
                  <el-descriptions-item v-if="item.Sign=='有货货主'" label="商品名称">
                    <el-form-item>
                      <el-select v-model.trim="item.Article_SerialNumber" placeholder="请选择商品" filterable
                        @change="Change_Unit_Price(index,item)" style="width: 100%">
                        <el-option v-for="(ite,index) in article.filter(i=>i.Sign=='2')" :key="index" :label="ite.Article_Name"
                          :value="ite.Article_SerialNumber"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-descriptions-item>
                <el-descriptions-item label="商品规格">
                    <el-form-item>
                        <el-select :disabled="item.specs==0" v-model.trim="item.Article_Specifications_SerialNumber"
                            placeholder="请选择规格" filterable @change="Change_Specifications_Name(index,item)" style="width: 100%">
                            <el-option v-for="(item,index) in item.specs" :key="index"
                                :label="item.Specifications_Name" :value="item.Article_Specifications_SerialNumber"></el-option>
                        </el-select>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="吊牌价">
                    <el-form-item>
                        <el-input v-model.trim="item.Unit_Price" disabled placeholder="零售价"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="销售单价">
                    <el-form-item>
                        <el-input @change="count(item)" :disabled="!item.Article_Specifications_SerialNumber" v-model.trim="item.Sales_Unit_Price" placeholder="请输入销售单价"></el-input>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="销售数量">
                    <el-form-item>
                        <el-input-number @change="count(item)" v-model.trim="item.Quantity" :min="1" style="width: 100%;" placeholder="请输入销售订单流水号"></el-input-number>
                    </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="总计">
                    <el-form-item>
                        <el-input disabled v-model.trim="item.Amount" style="width: 100%;" placeholder="金额总计"></el-input>
                    </el-form-item>
                </el-descriptions-item>
            </el-descriptions>
            <el-form-item class="form-operation">
                <el-button @click="window.history.back()">返回</el-button>
                <!-- <el-button type="success" @click="onExcel">导入</el-button> -->
                <el-button type="primary" :loading="loading" @click="submitForm('contract')">提交</el-button>
            </el-form-item>
        </el-form>
        <el-dialog title="导入订单" :visible.sync="dialogVisible" fullscreen="true">
            <input type="file" id="inputfile" name="file">
            <!-- -->
            <div>
                <el-table :data="tableData.slice((formData.page-1)*formData.limit,formData.page*formData.limit)" 
              height="calc(100vh - 200px)" style="width: 100% ;" stripe border :cell-style="tableCellStyle">
              <el-table-column label="序号" width="60" type="index" align="center"></el-table-column>
              <el-table-column prop="Dealer_Order_SerialNumber" width="100" label="订单号" align="center"></el-table-column>
              <el-table-column prop="Sales_Contacts" width="100" label="收货人" align="center"></el-table-column>
              <el-table-column prop="Sales_Phone" label="手机号码" align="center"></el-table-column>
              <el-table-column prop="Sales_Address" label="收货地址" align="center"></el-table-column>
              <el-table-column prop="Article_Name" label="商品名称" align="center"></el-table-column>
              <el-table-column prop="Specifications_Name" label="商品规格名称" align="center"></el-table-column>
              <el-table-column prop="Gfbm" label="规格编码" align="center"></el-table-column>
              <el-table-column prop="Quantity" label="发货数量" align="center"></el-table-column>
              <el-table-column prop="Sales_Unit_Price" label="一件代发价" align="center"></el-table-column>
              <el-table-column prop="Sales_Amount" label="总计" align="center"></el-table-column>
              <el-table-column prop="Dealer_SerialNumber" label="经销商" align="center">
                <template v-slot="{row}">
                  {{Dealer_Name(row.Dealer_SerialNumber)}}
                </template>
              </el-table-column>
              <el-table-column prop="Sales_Message" label="用户备注" align="center"></el-table-column>
              <el-table-column align="center" label="操作" width="120">
                <template slot-scope="scope">
                  <el-button @click.native.prevent="deleteRow(scope.$index, form2)" type="text" size="small">
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination style="position: fixed;bottom: 0;" background  @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :current-page="formData.page" :page-sizes="[10,50,100,500,1000]"
                :page-size="formData.limit" layout="total, sizes, prev, pager, next, jumper" :total="tableData.length">
            </el-pagination>
            </div>
            
            <div slot="footer" style="width: 100%; display: flex; justify-content: center;">
              <el-button @click="dialogVisible = false">取消</el-button>
              <el-button type="primary" @click="subFile">导入</el-button>
              <el-button type="primary" id="btn" :loading="loading" @click="submit">提交</el-button>
            </div>
          </el-dialog>
    </div>
    <!-- 依赖脚本 -->
    <script type="text/javascript" src="../../../js/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="../../../js/jquery.cookie.js"></script>
    <script type="text/javascript" src="../../../js/vue.min.js"></script>
    <script type="text/javascript" src="../../../elementUI/index.js"></script>
    <script type="text/javascript" src="../../../js/utils.js"></script>
    <script type="text/javascript" src="../../../js/ID_Validity.js"></script>
    <script type="text/javascript" src="../../../js/FileSaver.min.js"></script>
    <script type="text/javascript" src="../../../js/FileSaver.js"></script>
    <script type="text/javascript" src="../../../js/xlsx.full.min.js"></script>
    <script type="text/javascript" src="./js/Add.js"></script>
</body>

</html>